.PHONY: all clean


TOOL_HOME=/Applications/DevEco-Studio.app/Contents

#CC=${TOOL_HOME}/sdk/default/openharmony/native/llvm/bin/clang
CC=${TOOL_HOME}/sdk/default/openharmony/native/llvm/bin/clang --target=aarch64-linux-ohos -march=armv8a

#CC=${TOOL_HOME}/sdk/default/openharmony/native/llvm/bin/aarch64-unknown-linux-ohos-clang
#CXX=${TOOL_HOME}/sdk/default/openharmony/native/llvm/bin/aarch64-unknown-linux-ohos-clang++

GOROOT=/Volumes/Data/GitRepos/ohos_golang_go/default
GO=/Volumes/Data/GitRepos/ohos_golang_go/default/bin/go

BASE_FLAGS=-pthread -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -fPIC -ftls-model=global-dynamic  -v


CGO_CFLAGS=-I${TOOL_HOME}/sdk/default/openharmony/native/sysroot/usr/include/ -I${TOOL_HOME}/sdk/default/openharmony/native/sysroot/usr/include/aarch64-linux-ohos -g -O2 ${BASE_FLAGS}
CGO_LDFLAGS=-L${TOOL_HOME}/sdk/default/openharmony/native/sysroot/usr/lib/aarch64-linux-ohos


CGO_ENABLED=1

# 设置 GOOS 和 GOARCH
GOOS=openharmony
GOARCH=arm64

all: main_s main_a

main_s: main.c libCounter.so
	${CC} -o main_s $?

main_a: main.c libCounter.a
	${CC} -o main_a $?

libCounter.so: v3.go
	CGO_ENABLED=1 CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS="${CGO_LDFLAGS}" GOOS="${GOOS}" GOARCH="${GOARCH}" CC="${CC}" \
	${GO} build -buildmode=c-shared -asmflags="-tls=GD" -o $@ v3.go

libCounter.a: v3.go
	CGO_ENABLED=1 CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS="${CGO_LDFLAGS}" GOOS="${GOOS}" GOARCH="${GOARCH}" CC="${CC}" \
	${GO} build -buildmode=c-archive -asmflags="-tls=GD" -o $@ v3.go

clean:
	rm -f main libCounter.so libCounter.a libCounter.h main_a main_s v3
